package com.test.A12;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class A12 {

    interface Foo {
        void foo();
        int bar();
    }

     static class Target implements Foo {
        public void foo() {
            System.out.println("target foo");
        }
		@Override
		public int bar() {
			System.out.println("target bar");
			return 100;
		}

    }
    
     
    public static void main(String[] param) {
    	test2();
    }
    
    public static void test2() {
    	
    	Target target =new Target();//需要传进来目标对象
    	
    	$Proxy1 proxy =new $Proxy1(new InvocationHandler() {
			@Override
			public Object invoke(Object proxy,Method method, Object[] args)  throws Throwable{
				System.out.println("before.................."); 
				 return  method.invoke(target, args);//通过接口传入方法对象和方法的参数来通过反射得到具体的方法
				 //new Target().foo();
			}
    	});
    	proxy.foo();
    	proxy.bar();
    }
    
}

